package com.javatest.springbootquartz.config;

import com.javatest.springbootquartz.job.TestJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2019-07-04 下午5:39
 */
@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail testTaskDetail() {
        return JobBuilder.newJob(TestJob.class).withIdentity("bean test job").storeDurably().build();
    }

    @Bean
    public Trigger testTaskTrigger() {
        // 采用cron调度器, 5秒执行一次
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("*/5 * * * * ?");
        return TriggerBuilder.newTrigger().forJob(testTaskDetail())
                .withIdentity("bean test job")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
